<?php
include "config.php";//apikey配置文件
include "jd/JdClient.php";//请求文件
include "jd/RequestCheckUtil.php";//请求文件
include "jd/request/UnionOpenGoodsQueryRequest.php";//接口参数

$AppKey=$ApiConfig["AppKey"];
$AppSecret=$ApiConfig["AppSecret"];

$c = new JdClient();
$c->appKey = $ApiConfig["AppKey"];
$c->appSecret = $ApiConfig["AppSecret"];

$req = new UnionOpenGoodsQueryRequest();
$goodsReqDTO= array();
$goodsReqDTO["keyword"]="https://u.jd.com/BIUx98b";
$req->setGoodsReqDTO($goodsReqDTO);
// $req->setVersion("1.0");
$resp = $c->execute($req) -> jd_union_open_goods_query_responce -> queryResult;
print_r($resp);

// {
//     "code": 200,
//     "data": [{
//         "brandCode": "11540",
//         "brandName": "良品铺子",
//         "categoryInfo": {
//             "cid1": 1320,
//             "cid1Name": "食品饮料",
//             "cid2": 1583,
//             "cid2Name": "休闲食品",
//             "cid3": 1591,
//             "cid3Name": "坚果炒货"
//         },
//         "comments": 554706,
//         "commissionInfo": {
//             "commission": 20.67,
//             "commissionShare": 13.0,
//             "couponCommission": 19.37,
//             "endTime": 1646755199000,
//             "isLock": 1,
//             "plusCommissionShare": 13.0,
//             "startTime": 1646409600000
//         },
//         "couponInfo": {
//             "couponList": [{
//                 "bindType": 3,
//                 "discount": 10.0,
//                 "getEndTime": 1646755199000,
//                 "getStartTime": 1646409600000,
//                 "hotValue": 3,
//                 "isBest": 1,
//                 "isInputCoupon": 0,
//                 "link": "https://coupon.m.jd.com/coupons/show.action?linkKey=AAROH_xIpeffAs_-naABEFoef52ziYWDg6-BCJB2rNoyJKZ3Ipqia9aJU-1bKhOhzjdGLJsls8LkMJJzppe8E02dWjzmxw",
//                 "platformType": 0,
//                 "quota": 60.0,
//                 "useEndTime": 1646841599000,
//                 "useStartTime": 1646409600000
//             }]
//         },
//         "deliveryType": 0,
//         "forbidTypes": [0],
//         "goodCommentsShare": 98.0,
//         "imageInfo": {
//             "imageList": [{
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/217909/29/12745/194565/620f0b3fE0087fd8a/240673291e8c8f6a.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/148869/20/21306/159790/620f0009E52b7e9f2/b48ed5128a31701f.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/136317/26/26259/167687/61b94c87E055a4057/a2ab81834c0adee3.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/220593/30/7798/227303/61b94d46E1b7d7fef/ee47047bee741e0a.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/217483/17/7687/124952/61b94cf9Ef5c223d7/78f5c351a3ab4fc4.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/217450/28/7689/147317/61b94cf9E6df96dde/7d69f86051409a49.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/126285/10/27103/165215/61b94c88Ed3f0810e/50335c6cd33d2c1d.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/208277/4/12559/112068/61b94cf9E67e896f1/888b786eabeeacd0.jpg"
//             }, {
//                 "url": "https://img14.360buyimg.com/pop/jfs/t1/216454/19/7776/131345/61b94c88E152a7d3f/08f9f18aa5120f16.jpg"
//             }]
//         },
//         "inOrderComm30Days": 25623.87,
//         "inOrderCount30Days": 8257,
//         "isHot": 1,
//         "isJdSale": 0,
//         "materialUrl": "item.jd.com/10042212803297.html",
//         "owner": "p",
//         "pinGouInfo": {},
//         "pingGouInfo": {},
//         "priceInfo": {
//             "historyPriceDay": 46,
//             "lowestCouponPrice": 149.0,
//             "lowestPrice": 159.0,
//             "lowestPriceType": 3,
//             "price": 159.0
//         },
//         "seckillInfo": {
//             "seckillEndTime": 1646496000000,
//             "seckillOriPrice": 169.0,
//             "seckillPrice": 159.0,
//             "seckillStartTime": 1646395200000
//         },
//         "shopInfo": {
//             "afsFactorScoreRankGrade": "低",
//             "afterServiceScore": "8.63",
//             "commentFactorScoreRankGrade": "中",
//             "logisticsFactorScoreRankGrade": "高",
//             "logisticsLvyueScore": "9.50",
//             "scoreRankRate": "40.87",
//             "shopId": 25789,
//             "shopLabel": "0",
//             "shopLevel": 4.0,
//             "shopName": "良品铺子官方旗舰店",
//             "userEvaluateScore": "9.43"
//         },
//         "skuId": 10042212803297,
//         "skuName": "良品铺子 每日坚果礼盒750g 综合果仁零食大礼包生日礼包送女友生日礼物 坚果开心果白领孕妇零食 【专为家庭定制】全能妈妈综合果仁750g x1份",
//         "spuid": 10705804920,
//         "videoInfo": {}
//     }],
//     "message": "success",
//     "requestId": "o_0b11d703_l0deekwy_60096421",
//     "totalCount": 1
// }

function goods_query($key){
	global $AppKey;
	global $AppSecret;
	$c = new JdClient();
	$c->appKey = $AppKey;
	$c->appSecret = $AppSecret;
	
	$req = new UnionOpenGoodsQueryRequest();
	$goodsReqDTO= array();
	$goodsReqDTO["keyword"]=$key;
	$req->setGoodsReqDTO($goodsReqDTO);
	$resp = $c->execute($req);
	return json_decode($resp -> jd_union_open_goods_query_responce -> queryResult,true);
}